<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qqmllist.cpp -->
  <title>QQmlListProperty  类 | Qt QML 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtqml-index.html">Qt QML</a></td><td ><a href="qtqml-module.html">C++ 类</a></td><td >QQmlListProperty</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtqml-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#public-types">公用类型</a></li>
<li class="level1"><a href="#public-functions">公用函数</a></li>
<li class="level1"><a href="#public-variables">公用变量</a></li>
<li class="level1"><a href="#details">详细描述</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QQmlListProperty 类</h1>
<!-- $$$QQmlListProperty-brief -->
<p><a href="qqmllistproperty.html">QQmlListProperty</a> 类允许应用程序向QML公开<a href="../qtcore/qobject.html">QObject</a>派生类的类似列表的属性。<a href="#details">更多…</a></p>
<!-- @@@QQmlListProperty -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> 头文件：</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QQmlListProperty&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += qml</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Since:</td><td class="memItemRight bottomAlign">  Qt 5.0</td></tr></table></div><ul>
<li><a href="qqmllistproperty-members.html">所有成员的列表，包括继承的成员</a></li>
</ul>
<a name="public-types"></a>
<h2 id="public-types">公用类型</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#AppendFunction-typedef">AppendFunction</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#AtFunction-typedef">AtFunction</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#ClearFunction-typedef">ClearFunction</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> typedef </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#CountFunction-typedef">CountFunction</a></b></td></tr>
</table></div>
<a name="public-functions"></a>
<h2 id="public-functions">公用函数</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#QQmlListProperty">QQmlListProperty</a></b>(QObject *<i>object</i>, QList&lt;T *&gt; &amp;<i>list</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#QQmlListProperty-2">QQmlListProperty</a></b>(QObject *<i>object</i>, void *<i>data</i>, QQmlListProperty::AppendFunction <i>append</i>, QQmlListProperty::CountFunction <i>count</i>, QQmlListProperty::AtFunction <i>at</i>, QQmlListProperty::ClearFunction <i>clear</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#QQmlListProperty-3">QQmlListProperty</a></b>(QObject *<i>object</i>, void *<i>data</i>, QQmlListProperty::CountFunction <i>count</i>, QQmlListProperty::AtFunction <i>at</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#operator-eq-eq">operator==</a></b>(const QQmlListProperty&lt;T&gt; &amp;<i>other</i>) const</td></tr>
</table></div>
<a name="public-variables"></a>
<h2 id="public-variables">公用变量</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> QQmlListProperty::AppendFunction </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#append-var">append</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QQmlListProperty::AtFunction </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#at-var">at</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QQmlListProperty::ClearFunction </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#clear-var">clear</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QQmlListProperty::CountFunction </td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#count-var">count</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#data-var">data</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#dummy1-var">dummy1</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#dummy2-var">dummy2</a></b></td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QObject *</td><td class="memItemRight bottomAlign"><b><a href="qqmllistproperty.html#object-var">object</a></b></td></tr>
</table></div>
<a name="details"></a>
<!-- $$$QQmlListProperty-description -->
<div class="descr">
<h2 id="details">详细描述</h2>
<p><a href="qqmllistproperty.html">类允许应用程序向QML公开<a href="../qtcore/qobject.html">QObject</a>派生类的类似列表的属性。</p>
<p>QML有许多列表属性，其中可以分配多个对象值。QML中list属性的使用是这样的:</p>
<pre class="cpp">

  FruitBasket {
      fruit: <span class="operator">[</span>
          Apple {}<span class="operator">,</span>
          Orange{}<span class="operator">,</span>
          Banana{}
      <span class="operator">]</span>
  }

</pre>
<p><a href="qqmllistproperty.html">QQmlListProperty</a>封装了一组函数指针，它们表示QML可以在列表上执行的操作集——添加项、检索项和清除列表。在未来，可能会支持更多的操作。所有列表属性都必须实现append操作，但其他属性是可选的。</p>
<p>要提供list属性，C++类必须实现操作回调，然后从属性getter返回适当的<a href="qqmllistproperty.html">QQmlListProperty</a>值。列表属性应该没有setter。在上面的例子中，<a href="../qtcore/qobject.html#Q_PROPERTY">Q_PROPERTY</a>() 声明式将如下所示:</p>
<pre class="cpp">

  Q_PROPERTY(<span class="type"><a href="qqmllistproperty.html#QQmlListProperty">QQmlListProperty</a></span><span class="operator">&lt;</span>Fruit<span class="operator">&gt;</span> fruit READ fruit)

</pre>
<p>QML列表属性是类型安全的——在本例中，<code>Fruit</code> 是一个 <a href="../qtcore/qobject.html">QObject</a> 类型， <code>Apple</code>、 <code>Orange</code> 和 <code>Banana</code> 都是从该类型派生的。</p>
</div>
<p><b>还请参见</b><a href="qtqml-referenceexamples-properties-example.html">扩展QML - Object和列表属性类型示例</a>。</p>
<!-- @@@QQmlListProperty -->
<div class="types">
<h2>成员类型文档</h2>
<!-- $$$AppendFunction -->
<h3 class="fn" id="AppendFunction-typedef"><a name="AppendFunction-typedef"></a>typedef QQmlListProperty::<span class="name">AppendFunction</span></h3>
<p><code>void (*)(QQmlListProperty&lt;T&gt; *property, T *value)</code>的同义词。</p>
<p>将<i>value</i>追加到 <i>property</i>列表。</p>
<!-- @@@AppendFunction -->
<!-- $$$AtFunction -->
<h3 class="fn" id="AtFunction-typedef"><a name="AtFunction-typedef"></a>typedef QQmlListProperty::<span class="name">AtFunction</span></h3>
<p>Synonym for <code>T *(*)(QQmlListProperty&lt;T&gt; *property, int index)</code>.</p>
<p>返回列表<i>property</i>中的位置<i>index</i>元素。 </p>
<!-- @@@AtFunction -->
<!-- $$$ClearFunction -->
<h3 class="fn" id="ClearFunction-typedef"><a name="ClearFunction-typedef"></a>typedef QQmlListProperty::<span class="name">ClearFunction</span></h3>
<p><code>void (*)(QQmlListProperty&lt;T&gt; *property)</code>的同义词。</p>
<p>创建一个列表<i>property</i>。</p>
<!-- @@@ClearFunction -->
<!-- $$$CountFunction -->
<h3 class="fn" id="CountFunction-typedef"><a name="CountFunction-typedef"></a>typedef QQmlListProperty::<span class="name">CountFunction</span></h3>
<p><code>int (*)(QQmlListProperty&lt;T&gt; *property)</code>的同义词。</p>
<p>返回列表 <i>property</i>的元素数量。</p>
<!-- @@@CountFunction -->
</div>
<div class="func">
<h2>成员函数文档</h2>
<!-- $$$QQmlListProperty[overload1]$$$QQmlListPropertyQObject*QList<T*>& -->
<h3 class="fn" id="QQmlListProperty"><a name="QQmlListProperty"></a>QQmlListProperty::<span class="name">QQmlListProperty</span>(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>object</i>, <span class="type"><a href="../qtcore/qlist.html">QList</a></span>&lt;<span class="type">T</span> *&gt; &amp;<i>list</i>)</h3>
<p>用于从现有<a href="../qtcore/qlist.html">QList</a> 类型的<i>list</i>中生成<a href="qqmllistproperty.html">QQmlListProperty</a>值的便利构造函数。Convenience constructor for making a  value from an existing . The <i>list</i> reference must remain valid for as long as <i>object</i> exists. <i>object</i> must be provided.</p>
<p>通常不应该在生产代码中使用这个构造函数，因为可写的<a href="../qtcore/qlist.html">QList</a>违反了QML的内存管理规则。然而，这个构造函数在原型化时非常有用。</p>
<!-- @@@QQmlListProperty -->
<!-- $$$QQmlListProperty$$$QQmlListPropertyQObject*void*QQmlListProperty::AppendFunctionQQmlListProperty::CountFunctionQQmlListProperty::AtFunctionQQmlListProperty::ClearFunction -->
<h3 class="fn" id="QQmlListProperty-2"><a name="QQmlListProperty-2"></a>QQmlListProperty::<span class="name">QQmlListProperty</span>(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>object</i>, <span class="type">void</span> *<i>data</i>, <span class="type"><a href="qqmllistproperty.html#AppendFunction-typedef">QQmlListProperty::AppendFunction</a></span> <i>append</i>, <span class="type"><a href="qqmllistproperty.html#CountFunction-typedef">QQmlListProperty::CountFunction</a></span> <i>count</i>, <span class="type"><a href="qqmllistproperty.html#AtFunction-typedef">QQmlListProperty::AtFunction</a></span> <i>at</i>, <span class="type"><a href="qqmllistproperty.html#ClearFunction-typedef">QQmlListProperty::ClearFunction</a></span> <i>clear</i>)</h3>
<p>从一组操作函数<i>append</i>、 <i>count</i>、 <i>at</i>和<i>clear</i>构造一个<a href="qqmllistproperty.html">QQmlListProperty</a> 。可以传递一个不透明的<i>data</i> 句柄，该句柄可以从操作函数中访问。<i>object</i>存在时，list属性仍然有效。</p>
<p>空指针可以传递给任何函数。如果传入任何空指针，调试器将无法设计或更改列表。建议为所有函数提供有效的指针。</p>
<!-- @@@QQmlListProperty -->
<!-- $$$QQmlListProperty$$$QQmlListPropertyQObject*void*QQmlListProperty::CountFunctionQQmlListProperty::AtFunction -->
<h3 class="fn" id="QQmlListProperty-3"><a name="QQmlListProperty-3"></a>QQmlListProperty::<span class="name">QQmlListProperty</span>(<span class="type"><a href="../qtcore/qobject.html">QObject</a></span> *<i>object</i>, <span class="type">void</span> *<i>data</i>, <span class="type"><a href="qqmllistproperty.html#CountFunction-typedef">QQmlListProperty::CountFunction</a></span> <i>count</i>, <span class="type"><a href="qqmllistproperty.html#AtFunction-typedef">QQmlListProperty::AtFunction</a></span> <i>at</i>)</h3>
<p>从一组操作函数<i>count</i> 和 <i>at</i>构造一个只读的<a href="qqmllistproperty.html">QQmlListProperty</a>。可以传递一个不透明的<i>data</i>句柄，该句柄可以从操作函数中访问。<i>object</i>存在时，list属性仍然有效。</p>
<!-- @@@QQmlListProperty -->
<!-- $$$operator==[overload1]$$$operator==constQQmlListProperty<T>& -->
<h3 class="fn" id="operator-eq-eq"><a name="operator-eq-eq"></a><span class="type">bool</span> QQmlListProperty::<span class="name">operator==</span>(const <span class="type"><a href="qqmllistproperty.html#QQmlListProperty">QQmlListProperty</a></span>&lt;<span class="type">T</span>&gt; &amp;<i>other</i>) const</h3>
<p>如果此<a href="qqmllistproperty.html">QQmlListProperty</a> 与<i>other</i>属性相等，则返回true，否则为false。</p>
<!-- @@@operator== -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
